<template>
	<view>
		<u-button @tap="btnSelect" type="primary">选择</u-button>
	</view>
</template>

<script>
	export default {
		props: {
			value: {
				type: String,
				default: ""
			},
			// 产品id
			spuId: {
				type: String,
				default: null
			},
			disabled: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				insVal: ""
			}
		},
		created() {
			const key = "on-selected-goods-width-gram"
			uni.$on(key, data => {
				this.$emit("on-selected", data)
			})
			this.$once('hook:beforeDestroy', () => {
				console.log("移除监听", key)
				uni.$off(key)
			})
		},
		watch: {
			"value": {
				handler(val) {
					this.insVal = val
				},
				immediate: true
			}
		},
		methods: {
			btnSelect() {
				const spuId = this.spuId
				if (!spuId) return uni.showToast({
					icon:'error',
					title: "请先选择产品"
				})
				this.$Router.push({
					path: "/selects/goodsWidthGramWeight",
					query: {
						spuId
					}
				})
			}
		}
	}
</script>

<style>
</style>